from django.conf import settings
from django.forms import ModelForm
from tinymce.widgets import TinyMCE

from capabilities import formfield_callbacks

from cm_s.models import Page, MainPage

class PageForm(ModelForm):
    formfield_callback = formfield_callbacks.html5
    
    def __init__(self, *args, **kwargs):
        super(PageForm, self).__init__(*args, **kwargs)
        self.fields['title'].widget.attrs['autofocus'] = 'autofocus'
        self.fields['body'].widget = TinyMCE(attrs=settings.S_TE_TINYMCE_DEFAULT_ATTRS)

    class Meta:
        model = Page

class MainPageForm(ModelForm):
    
    class Meta:
        model = MainPage